package com.security03.handler;

import com.alibaba.fastjson.JSONArray;
import com.security03.util.ResultCode;
import com.security03.util.ResultTool;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@Component
public class NotLoginAuthentication implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
        PrintWriter out = response.getWriter();
        out.println(JSONArray.toJSONString(ResultTool.fail(ResultCode.USER_NOT_LOGIN)));
    }
}